package com.nexus.ai.embed;

import com.nexus.ai.embed.properties.NexusEmbedProperties;
import com.nexus.ai.embed.properties.NexusEmbeddingModel;
import com.nexus.core.properties.ExternalPropertySourceFactory;
import org.springframework.ai.ollama.OllamaEmbeddingModel;
import org.springframework.ai.ollama.api.OllamaApi;
import org.springframework.ai.ollama.api.OllamaEmbeddingOptions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;


/**
 * 向量模型配置
 * @Date 2025/9/28 18:05
 * @Author luzhengning
 **/
@Configuration
@PropertySource(
        name = "embed.properties",
        value = "classpath*:embed-pro.properties",encoding = "UTF8",
        factory = ExternalPropertySourceFactory.class,
        ignoreResourceNotFound = true
)
public class NexusEmbedConfig {

    @Autowired
    private NexusEmbedProperties  properties;

    @Bean
    public OllamaEmbeddingModel ollamaEmbeddingModel() {
        if(properties.getModels().containsKey("qwen3")==false){
            return null;
        }
        NexusEmbeddingModel model = properties.getModels().get("qwen3");
        OllamaApi embeddingApi = OllamaApi.builder().baseUrl(model.getBaseUrl()).build();
        return OllamaEmbeddingModel.builder()
                .ollamaApi(embeddingApi)
                .defaultOptions(OllamaEmbeddingOptions.builder().model(model.getModel()).build())
                .build();
    }
}
